﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Honestysoft.Financing.Model;
using Honestysoft.BaseObject;
using Honestysoft.Baseframework.WebUI;

namespace Honestysoft.Financing.WebUI.Module.Contract
{
    public partial class ContractConfirmInfo : BasePage
    {
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private const string empty = "<span style='color:red;font-weight:700'>缺少该项数据？</span>";

        /// <summary>
        /// 绑定页面
        /// </summary>
        private void Bind()
        {
            BD_Contract obj = new BaseBusinessLogic<BD_Contract>().GetEntity(Request.QueryString["ID"]);
            if (obj == null) { return; }
            btnEdit.Attributes.Add("onclick", "javascript:openDialog('" + Globals.Home + "Module/Contract/ContractEdit_ToDatabase.aspx?ID=" + obj.ID + "&FunctionID=" + FunctionID + "',800,600,'修改合同信息');return false;");

            btnConfirm.Attributes.Add("onclick", "javascript:if(checkRequired()){return openDialog('" + Globals.Home + "Module/Contract/ContractConfirm.aspx?ID=" + Request.QueryString["ID"] + "&FunctionID=" + FunctionID + "',560,500,'确认初始化');}else{return false;}");
            btnViewConfirm.Attributes.Add("onclick", "javascript:openDialog('" + Globals.Home + "Module/Contract/ContractConfirm.aspx?ID=" + Request.QueryString["ID"] + "&FunctionID=" + FunctionID + "',560,500,'查看确认意见');return false;");

            if (obj.IsInit)
            {
                btnConfirm.Enabled = false;
            }
            else
            {
                btnViewConfirm.Enabled = false;
            }

            _ID = obj.ID;
            //_ProjectID = obj.ProjectID;
            _ProjectID = new Honestysoft.Financing.BusinessLogic.Project(Globals.CurrentConnStringName).GetProjectName(obj.ProjectID);

            _ContractCategory = Honestysoft.DictionaryHelper.DictionaryInstance.GetDictionaryText(obj.ContractCategory);
            _Code = obj.Code;
            _Name = obj.Name;
            _SignDate = obj.SignDate.HasValue ? obj.SignDate.Value.ToString("yyyy-MM-dd") : "";
            _TotalPrice = obj.TotalPrice.ToString("0.00");
            _ChangePrice = obj.ChangePrice.HasValue ? obj.ChangePrice.Value.ToString("0.00") : "";
            _Stage = obj.Stage.ToString("0.00");
            _IsZD = ScriptHelper.Image.GetBooleanImage(obj.IsZD);

            _ReserveAmount = obj.ReserveAmount.HasValue ? obj.ReserveAmount.Value.ToString("0.00") : "";
            //_Contractor = obj.Contractor;
            _Contractor = new Honestysoft.Financing.BusinessLogic.Reports(Globals.CurrentConnStringName).GetCompanyName(obj.Contractor);

            _PaymentCondition = obj.PaymentCondition;
            if (!string.IsNullOrEmpty(obj.Remark))
            {
                _Remark = obj.Remark.ToString().Replace("\n", "<br/>");
            }
            _BankAccount = string.IsNullOrEmpty(obj.BankAccount) ? empty : obj.BankAccount;
            _BankName = string.IsNullOrEmpty(obj.BankName) ? empty : obj.BankName;
        }

        /// <summary>
        /// 标识
        /// </summary>
        protected string _ID = "";
        /// <summary>
        /// 项目代码
        /// </summary>
        protected string _ProjectID = "";
        /// <summary>
        /// 合同类别
        /// </summary>
        protected string _ContractCategory = "";
        /// <summary>
        /// 合同编号
        /// </summary>
        protected string _Code = "";
        /// <summary>
        /// 合同名称
        /// </summary>
        protected string _Name = "";
        /// <summary>
        /// 签订日期
        /// </summary>
        protected string _SignDate = "";
        /// <summary>
        /// 合同总价
        /// </summary>
        protected string _TotalPrice = "";
        /// <summary>
        /// 变更后总价
        /// </summary>
        protected string _ChangePrice = "";
        /// <summary>
        /// 前期累计拨付资金
        /// </summary>
        protected string _Stage = "";
        /// <summary>
        /// 是否暂定金额
        /// </summary>
        protected string _IsZD = "";
        /// <summary>
        /// 包含预留金
        /// </summary>
        protected string _ReserveAmount = "";
        /// <summary>
        /// 施工单位
        /// </summary>
        protected string _Contractor = "";
        /// <summary>
        /// 备注
        /// </summary>
        protected string _Remark = "";
        /// <summary>
        /// 付款条件
        /// </summary>
        protected string _PaymentCondition = "";

        protected string _BankName = "";
        protected string _BankAccount = "";

        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            Bind();
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            Bind();
        }
    }
}